import { Request, Response } from 'express';
import { Req, Res, Get, Controller, Param, QueryParams } from 'routing-controllers';
import { Container } from 'typedi';
import { LogService } from '@services/log.service';
import { ApiResponseBuilder } from '@utils/api-response-builder';
import { OpenAPI } from 'routing-controllers-openapi';
import { RequiredPerm } from '@decorators/perm.decorator';
import { AuditLogPageParams } from '@/dtos';

@Controller('/audit-Log')
export class AuditLogController {
  public service = Container.get(LogService);

  @Get('/page')
  @RequiredPerm('log:page')
  @OpenAPI({ summary: '分页查询日志' })
  async findAll(@Req() req: Request, @Res() res: Response, @QueryParams() dto: AuditLogPageParams) {
    const { data, total } = await this.service.findAll(dto);
    return new ApiResponseBuilder(req, res).paginate(data, total, dto.pageNum, dto.pageSize);
  }

  @Get('/detail/:id')
  @RequiredPerm('log:detail')
  @OpenAPI({ summary: '分页查询日志' })
  async findDetail(@Param('id') id: string, @Req() req: Request, @Res() res: Response) {
    const data = await this.service.findOne(id);
    return new ApiResponseBuilder(req, res).success(data);
  }
}
